package main
import (
	"strconv"
	"fmt"
)

type Element interface {}
type List[] Element

type Person struct {
	name string
	age int
}

func (p Person) string() string{
	return "name:" + p.name + ",age:" + strconv.Itoa(p.age) + "years"
}

func main() {
	test2_6_1()
	test2_6_2()
}

func test2_6_1()  {
	list:= make(List,3)
	list[0]=1
	list[1]="hello"
	list[2]=Person{"denis",10}
	for index ,element := range list{
		if value,ok := element.(int);ok{
			fmt.Printf("list[%d] is an int and its value is %d\n", index, value)
		}else if value, ok := element.(string); ok {
			fmt.Printf("list[%d] is a string and its value is %s\n", index, value)
		} else if value, ok := element.(Person); ok {
			fmt.Printf("list[%d] is a Person and its value is %s\n", index, value)
		} else {
			fmt.Printf("list[%d] is of a different type\n", index)
		}
	}
}

func test2_6_2()  {
	list:= make(List,3)
	list[0]=1
	list[1]="hello"
	list[2]=Person{"denis",10}
	for index ,element := range list {
		switch value:=element.(type) {
		case int:
			fmt.Printf("list[%d] is an int and its value is %d\n", index, value)
		case string:
			fmt.Printf("list[%d] is a string and its value is %s\n", index, value)
		case Person:
			fmt.Printf("list[%d] is a Person and its value is %s\n", index, value)
		default:
			fmt.Println("list[%d] is of a different type", index)
			
		}
	}
}


